package bueu.bexl;

import static bueu.bexl.utils.TypeUtils.booleanValue;

public class AndExpr extends BinayExpr {

	public AndExpr(final BexlExpr expr1, final BexlExpr expr2) {
		super(expr1, expr2);
	}

	@Override
	protected final Object eval(final BexlCtx ctx, final Object current, final boolean set, 
			final Object newValue) throws BexlException {
		
		boolean value1 = booleanValue(getExpr1().eval(ctx, current, set, newValue));
		
		if (value1) {
			return booleanValue(getExpr2().eval(ctx, current, set, newValue));
		}
		
		return false;
	}

	@Override
	protected final Object evaluate(Object value1, Object value2) {
		return null; // No usada
	}
	
	@Override
	public final String toString() {
		return toString("&&");
	}
}
